<?php
/**
 * Acl plugin checks authorization
 *
 * @author     Mario Schillermann <info@rockit-flash.com>
 * @encoding   UTF-8 äöüßÖÄÜ
 * @copyright  © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license    GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @uses       Zend_Controller_Plugin_Abstract
 * @category   Library
 * @package    App
 * @subpackage Plugin
 * @todo
 */

class App_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
    /**
     * Check access authorization
     * 
     * @param  Zend_Controller_Request_Abstract $request
     * @throws Exception Not access
     *
     * @return void
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    { 
        $resource = $request->getModuleName() . "_" . $request->getControllerName();
        $user = Zend_Auth::getInstance()->getStorage()->read();

        if (!$user["Zend_Acl"]->isAllowed(null, $resource, $request->getActionName())) {

            $request->setModuleName("rockitbos")
                    ->setControllerName("message")
                    ->setActionName("access");
        }
    }
}